package peace.transport.xmlrpc.type
{
	import peace.transport.xmlrpc.Xmlrpc;

public dynamic class XmlrpcStruct extends Object
{
	
	public function get xml ():XML
	{
		var xml:XML = <struct/>;
			
		for (var key:String in this)
		{
			xml.* += <member>
						<name>{key}</name>
						<value>{Xmlrpc.encodeValue(this[key])}</value>
					 </member>
		}
		return xml;
	}
	

	public function XmlrpcStruct (object:Object = null)
	{
		if (object)
		{
			for (var name:String in object)
			{
				this[name] = object[name];
			}
		}
	}
	/**
	 * 
	 * @param xml
	 * @return 
	 * 
	 */	
	public static function parse (xml:XML):XmlrpcStruct
	{
		var obj:XmlrpcStruct = new XmlrpcStruct();
		for each (var node:XML in xml.member)
		{
			obj[node.name[0]] = Xmlrpc.decodeValue(node.value.*[0])
		}
		return obj;
	}
	
	

}

}